#!/usr/bin/perl

use strict;
use warnings;
require 'forum_common.pl';

connect_to_database() or bad_deal();
my $user = get_current_user(get_sess_id());

record_this_hit();

print header($forum::http_header), forum_start(forum_cpanel($user));


my $boards;
unless ($boards = get_boards())
{
	print forum_error();
	goto gameover;
}

print '<div id="boards">';
my $null = '---';
for my $board (@$boards)
{
	my ($title,$descr,$lp_dt_posted,$lpu_usernm,$lpt_title,$lp_label,
					  $lt_dt_started,$ltu_usernm,$lt_title,$lt_label);
	($title,$descr)=(escapeHTML($board->{TITLE}),escapeHTML($board->{DESCR}));
	($lp_label,$lt_label) = ('Last Post:', 'Last Topic:');
	if (defined $board->{LP_ID})
	{
		$lp_label = a({-href=>"post.cgi?id=$board->{LP_ID}"}, $lp_label);
		
		$lp_dt_posted = timefmt($board->{LP_DT_POSTED});
		$lpu_usernm = a({-href=>"member.cgi?id=$board->{LPU_ID}"},
						escapeHTML($board->{LPU_USERNM}));
		$lpt_title = a({-href=>"topic.cgi?id=$board->{LPT_ID}"},
						escapeHTML($board->{LPT_TITLE}));
	}
	else
	{
		$lp_dt_posted = $lpu_usernm = $lpt_title = $null;
	}
	if (defined $board->{LT_ID})
	{
		$lt_label = a({-href=>"topic.cgi?id=$board->{LT_ID}"}, $lt_label);
		
		$lt_dt_started = timefmt($board->{LT_DT_STARTED});
		$ltu_usernm = a({-href=>"member.cgi?id=$board->{LTU_ID}"},
						escapeHTML($board->{LTU_USERNM}));
		$lt_title = a({-href=>"topic.cgi?id=$board->{LT_ID}"},
						escapeHTML($board->{LT_TITLE}));
	}
	else
	{
		$lt_dt_started = $ltu_usernm = $lt_title = $null;
	}

	print
	div({-class=>'board'},
		div({-class=>'info'},
			div({-class=>'title'},
			  a({-href=>"board.cgi?id=$board->{ID}",-class=>'strong'},$title)),
			div({-class=>'descr'}, $descr)),
		div({-class=>'data'},
		 div({-class=>'ftable', -style=>'border-spacing:1em 1px'},
		  div({-class=>'ftr'},
			div({-class=>'ftd ralign'}, 'Posts:'),
			div({-class=>'ftd'}, span({-class=>'nposts'},$board->{NUM_POSTS})),
			div({-class=>'ftd ralign'}, $lp_label),
			div({-class=>'ftd'}, span({-class=>'dt'}, $lp_dt_posted)),
			div({-class=>'ftd ralign'}, 'In:'),
			div({-class=>'ftd'}, span({-class=>'title'}, $lpt_title)),
			div({-class=>'ftd ralign'}, 'By:'),
			div({-class=>'ftd'}, span({-class=>'usernm'}, $lpu_usernm))
			),
		  div({-class=>'ftr'},
			div({-class=>'ftd ralign'}, 'Topics:'),
			div({-class=>'ftd'},span({-class=>'ntopics'},$board->{NUM_TOPICS})),
			div({-class=>'ftd ralign'}, $lt_label),
			div({-class=>'ftd'}, span({-class=>'dt'}, $lt_dt_started)),
			div({-class=>'ftd ralign'}, 'Title:'),
			div({-class=>'ftd'}, span({-class=>'title'}, $lt_title)),
			div({-class=>'ftd ralign'}, 'By:'),
			div({-class=>'ftd'}, span({-class=>''}, $ltu_usernm))
			)
		)));
}
print '</div>';

gameover:
print forum_end();
forum_disconnect();
